package com.hjb.service.controller.siteuseraccount;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.hjb.service.domain.siteuser.SiteUser;
import com.hjb.service.domain.siteuser.SiteUserExperienceLog;
import com.hjb.service.domain.siteuser.SiteUserExperienceLogExample;
import com.hjb.service.siteuseraccount.SiteUserExperienceLogService;
import com.hjb.service.utils.MapUtil;

/**
 * 体验金 Controller
 * @author zhangxl
 * @date 2017-08-04
 * @version 1.0
 */
@RestController
@RequestMapping("/experience")
public class SiteUserExperienceController {

	private Logger log = LoggerFactory.getLogger(getClass());
	@Autowired
	private SiteUserExperienceLogService userExperienceLogService;
	
	/**
	 * 体验金明细列表
	 * @param request
	 * @return
	 */
	@RequestMapping("/log/list")
	@ResponseBody
	public Map<String, Object> profitList(HttpServletRequest request){
		Map<String,Object> resMap =MapUtil.getRetMap();
		Map<String,Object> dataMap = new HashMap<String, Object>();
		try {
			SiteUser siteUser = (SiteUser) request.getSession().getAttribute("siteUser");
			//会话过期
			if (siteUser == null) {
				resMap.put("result_code", MapUtil.INTF_ERR_CODE_416);
				resMap.put("result_info", "会话过期");
				return resMap;
			}
			
			SiteUserExperienceLogExample logExample = new SiteUserExperienceLogExample();
			logExample.createCriteria().andUserIdEqualTo(siteUser.getUserId());
			logExample.setOrderByClause("create_time desc");
			
			List<SiteUserExperienceLog> logList = userExperienceLogService.queryExperienceLog(logExample);
			
			dataMap.put("logList", logList);
			resMap.put("data", dataMap);
		} catch (Exception e) {
			log.info(e.getMessage());
			resMap.put("result_code", MapUtil.INTF_ERR_CODE);
			resMap.put("result_info", "调用失败");	
		}
		
		return resMap;
		
	}
}
